package cn.lbd.api.designMode.proxy.dynamicproxy.rent;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationHandler implements InvocationHandler {

    //被代理的接口。真实对象
    private Rent rent;

    public void setRent(Rent rent) {
        this.rent = rent;
    }

    public Object getProxy(){
        Object proxy = Proxy.newProxyInstance(rent.getClass().getClassLoader(), rent.getClass().getInterfaces(), this);
        return proxy;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        Double money=(Double) objects[0];
        money=money*0.8;
        System.out.println("代理商帮忙选房");
        Object value = method.invoke(rent, money);
        System.out.println("代理商赚差价");
        String name = method.getName();
        System.out.println(name);
        return value;
    }
}
